local _M = {}

function _M.check(value, rules)
    local checks = {
        required = function(v) return v ~= nil and v ~= "" end,
        email = function(v) return v:match("[^@]+@[^@]+%.[^@]+") end,
        min_len = function(v, len) return #v >= tonumber(len) end
    }

    for rule in rules:gmatch("[^|]+") do
        local name, param = rule:match("([%w_]+):?(.*)")
        if not checks[name](value, param) then
            return false
        end
    end
    
    return true
end

return _M